package com.cskaoyan.servlet;

import com.cskaoyan.bean.vo.StatVo;
import com.cskaoyan.service.StatService;
import com.cskaoyan.service.StatServiceImpl;
import com.cskaoyan.util.ResponseUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author stone
 * @date 2023/03/20 16:09
 */
@WebServlet("/admin/stat/*")
public class AdminStatServlet extends WdBaseServlet {
    private StatService statService = new StatServiceImpl();
    @Override
    protected void handle(String operation, HttpServletRequest request, HttpServletResponse response) throws IOException {
        switch (operation) {
            case "/user":
                user(request, response);
                break;
        }
    }

    private void user(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Map> rows = statService.statUser();
        String[] columns = new String[]{"day", "users"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response,statVo);
    }
}

